package team.seekers.hula.course.structure.section.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.BaseDO;
import team.seekers.hula.course.structure.section.entity.dto.SectionDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(SectionDOField.TABLE_NAME)
public class SectionDO extends BaseDO {

    private static final long serialVersionUID = 1L;

    @TableId(value = SectionDOField.ID, type = IdType.ASSIGN_ID)
    private String id;

    @TableField(SectionDOField.NAME)
    private String name;

    /**所属的课程id*/
    @TableField(SectionDOField.COURSE_ID)
    private String courseId;

    /**所属的章id*/
    @TableField(SectionDOField.CHAPTER_ID)
    private String chapterId;

    /**节顺序（第几节）*/
    @TableField(SectionDOField.SEQUENCE)
    private Integer sequence;

    @TableField(SectionDOField.TYPE)
    private Integer type;

    /**是否开放*/
    @TableField(SectionDOField.OPEN)
    private Integer open;

    @TableField(SectionDOField.DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(value = SectionDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = SectionDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    public static List<SectionDTO> toDTOList(List<SectionDO> list) {
        ArrayList<SectionDTO> sectionDTOS = new ArrayList<>();
        for (SectionDO sectionDO : list) {
            SectionDTO sectionDTO = new SectionDTO();
            BeanUtils.copyProperties(sectionDO,sectionDTO);
            sectionDTOS.add(sectionDTO);
        }
        return sectionDTOS;
    }

    public static SectionDO fromDTO(SectionDTO sectionDTO) {
        SectionDO sectionDO = new SectionDO();
        BeanUtils.copyProperties(sectionDTO,sectionDO);
        return sectionDO;
    }
}
